<ui:composition template="/templates/contentTempl.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a="http://richfaces.org/a4j" xmlns:r="http://richfaces.org/rich"
	xmlns:t="http://myfaces.apache.org/tomahawk">
	<ui:define name="title">Администратиране на модул</ui:define>
	<ui:define name="pageLabel">
		<f:view>
			<h:outputText value="Администратиране на модул" />
		</f:view>
	</ui:define>
	<ui:define name="topCenterSideContent">
		<a:keepAlive beanName="regModul" />
		<f:view>
			<h:form id="frmsearchObj">
				<h:panelGrid width="100%" id="mainPanel">
					<h:panelGrid columns="1" width="100%">
						<ui:include src="/pages/moduls/modulTemplates/modulTeplate.xhtml">
							<ui:param name="backingBean" value="${regModul}" />
						</ui:include>
						<h:panelGrid styleClass="container-right">
							<a:commandButton id="btnId" value="Запис на Модул" type="submit"
								action="#{regModul.saveModul}" reRender="mainPanel"
								rendered="#{!regModul.saveModul}" />
						</h:panelGrid>

						<h:panelGrid columns="1" rendered="#{regModul.saveModul}"
							width="90%">

							<h:panelGrid width="90%">

								<r:dataTable id="tblResults" width="100%" var="gr"
									onRowMouseOver="this.className='dataTableRowMouseOver'"
									onRowMouseOut="this.className='dataTableRowMouseOut'"
									rowKeyVar="selectedGr" value="#{regModul.modulMElements}">

									<f:facet name="header">
										<r:columnGroup>
											<r:column colspan="5">
												<h:outputText
													value="Характеристики на модула: #{regModul.modulname}" />
											</r:column>
											<r:column breakBefore="true">
												<h:outputText value="Пореден номер" />
											</r:column>
											<r:column>
												<h:outputText value="Име" />
											</r:column>
											<r:column>
												<h:outputText value="Тип" />
											</r:column>
											<r:column>
												<h:outputText value="Задължително поле" />
											</r:column>
											<r:column>
												<h:outputText value="Действия" />
											</r:column>
										</r:columnGroup>
									</f:facet>

									<r:columnGroup>
										<r:column colspan="4" style="font-weight: bold;">
											<h:outputText value="Група: #{gr.modulElements.elementname}" />
										</r:column>
										<r:column>
											<h:panelGrid columns="2">
												<a:commandButton id="btnEditGroup"
													style="background-color:#EEE;border-color:#DDD;margin-right:5px;"
													action="#{regModul.navToEditGroup}" value="Промяна">
													<f:setPropertyActionListener value="#{selectedGr}"
														target="#{regModul.selectedTableGroup}" />
												</a:commandButton>
												<a:commandButton id="btnDeleteGroup" value="Изтриване"
													style="background-color:#EEE;border-color:#DDD;margin-right:5px;"
													oncomplete="Richfaces.showModalPanel('dlgDeleteContext')">
													<f:setPropertyActionListener value="#{selectedGr}"
														target="#{regModul.selectedTableGroup}" />
												</a:commandButton>
											</h:panelGrid>
										</r:column>
									</r:columnGroup>

									<r:subTable
										onRowMouseOver="this.className='dataTableRowMouseOver'"
										onRowMouseOut="this.className='dataTableRowMouseOut'"
										var="attr" value="#{gr.modulElements.attributeses}"
										rowKeyVar="selectedAttr">
										<r:column>
											<h:outputText value="#{attr.ordering}" />
										</r:column>
										<r:column>
											<h:outputText value="#{attr.attributeName}" />
										</r:column>
										<r:column>
											<h:outputText value="#{attr.attributeType.attributeName}" />
										</r:column>
										<r:column>
											<h:outputText value="#{attr.isRequired ? 'да' : 'не'}" />
										</r:column>
										<r:column>
											<h:panelGrid >
												<h:panelGrid columns="2" styleClass="container-right">
													<a:commandButton id="btnEditAttribute"
														style="background-color:#EEE;border-color:#DDD;margin-right:5px;"
														action="#{regModul.navToEditAttribute}" value="Промяна">
														<f:setPropertyActionListener value="#{selectedAttr}"
															target="#{regModul.selectedTableAttribute}" />
														<f:setPropertyActionListener value="#{selectedGr}"
															target="#{regModul.selectedTableGroup}" />
													</a:commandButton>
													<a:commandButton id="btnDeleteAttribute"
														style="background-color:#EEE;border-color:#DDD;margin-right:5px;"
														value="Изтриване"
														oncomplete="Richfaces.showModalPanel('dlgDeleteAttribute');">
														<f:setPropertyActionListener value="#{selectedAttr}"
															target="#{regModul.selectedTableAttribute}" />
														<f:setPropertyActionListener value="#{selectedGr}"
															target="#{regModul.selectedTableGroup}" />
													</a:commandButton>
												</h:panelGrid>
											</h:panelGrid>
										</r:column>
									</r:subTable>

								</r:dataTable>
							</h:panelGrid>
							<h:panelGrid styleClass="container-right">
								<h:panelGrid columns="2">
									<a:commandButton id="btnIdGroup" value="Създаване на група"
										type="submit" action="#{regModul.newGroup}" />
									<a:commandButton id="btnIdAttribute"
										value="Създаване на атрибут" type="submit"
										action="#{regModul.newAttribute}" />
								</h:panelGrid>
							</h:panelGrid>
						</h:panelGrid>
					</h:panelGrid>
				</h:panelGrid>
			</h:form>

			<!-- Потвърждаване на контекст -->
			<r:modalPanel id="dlgDeleteContext" autosized="true">
				<f:facet name="header">
					<h:panelGroup>
						<h:outputText value="Изтриване на група на модула" />
					</h:panelGroup>
				</f:facet>
				<f:facet name="controls">
					<h:panelGroup>
						<h:graphicImage value="/css/images/close.png"
							styleClass="hidelink" id="hideLinkdlgDeleteContext" />
						<r:componentControl for="dlgDeleteContext"
							attachTo="hideLinkdlgDeleteContext" operation="hide"
							event="onclick" />
					</h:panelGroup>
				</f:facet>
				<a:form id="frmDlgDeleteContext">
					<h:panelGrid columns="1">
						<r:panel>
							<h:outputText
								value="Сигурни ли сте, че искате да изтриете тази група?" />
						</r:panel>
						<h:panelGroup>
							<a:commandButton id="btnConfirmDelete"
								action="#{regModul.removeGroup}" type="submit" value="Изтриване"
								reRender="frmResultsMarketingServiceBottom"
								oncomplete="Richfaces.hideModalPanel('dlgDeleteContext')">
							</a:commandButton>
							<r:spacer styleClass="space-horizontal" />
							<a:commandButton id="btnCancelgConfirmContext" value="Отказ"
								type="button"
								onclick="Richfaces.hideModalPanel('dlgDeleteContext')">
							</a:commandButton>
						</h:panelGroup>
					</h:panelGrid>
				</a:form>
			</r:modalPanel>

			<!-- Изтриване на атрибут на маркетингова услуга -->
			<r:modalPanel id="dlgDeleteAttribute" autosized="true">
				<f:facet name="header">
					<h:panelGroup>
						<h:outputText value="Изтриване на атрибут на модула" />
					</h:panelGroup>
				</f:facet>
				<f:facet name="controls">
					<h:panelGroup>
						<h:graphicImage value="/css/images/close.png"
							styleClass="hidelink" id="hideLinkDlgDeleteAttribute" />
						<r:componentControl for="dlgDeleteAttribute"
							attachTo="hideLinkDlgDeleteAttribute" operation="hide"
							event="onclick" />
					</h:panelGroup>
				</f:facet>
				<a:form id="frmDlgDeleteAttribute">
					<h:panelGrid columns="1">
						<r:panel>
							<h:outputText
								value="Сигурни ли сте, че искате да изтриете този атрибут?" />
						</r:panel>
						<h:panelGroup>
							<a:commandButton id="btnConfirmDelete"
								action="#{regModul.removeAttribute}" type="submit"
								value="Изтриване" reRender="frmResultsMarketingServiceBottom"
								oncomplete="Richfaces.hideModalPanel('dlgDeleteAttribute')">
							</a:commandButton>
							<r:spacer styleClass="space-horizontal" />
							<a:commandButton id="btnCancelConfirmAttribute" value="Отказ"
								type="button"
								onclick="Richfaces.hideModalPanel('dlgDeleteAttribute')">
							</a:commandButton>
						</h:panelGroup>
					</h:panelGrid>
				</a:form>
			</r:modalPanel>

		</f:view>
	</ui:define>
</ui:composition>